<?php
namespace app\index\command;

use app\index\controller\Dooroperate;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;

class Serialmessage extends Command
{
    protected function configure()
    {
        $this->setName('serialmessage')->setDescription('C++程序调用此接口上报串口消息')->setAliases(['sm'])
            ->addOption('msg','m',Option::VALUE_OPTIONAL,'串口消息')
            ->addOption('port','p',Option::VALUE_OPTIONAL,'端口号');
    }

    protected function execute(Input $input, Output $output)
    {
        $msg = $input->getOption('msg');
        $port = $input->getOption('port');
        dta($msg,"CLI入口收到[COM{$port}]消息");
        $cmd = "php " . dirname(dirname(dirname(__DIR__))) . "/public/index.php index/dooroperate/msgreport/port/" . $port . "/msg/" . $msg;
        $output->writeln($cmd);
        passthru($cmd);
    }
}